package palidino76.rs2.player.combat;

import palidino76.rs2.*;
import palidino76.rs2.io.*;
import palidino76.rs2.util.*;
import palidino76.rs2.npcs.*;
import palidino76.rs2.npcs.combat.*;
import palidino76.rs2.player.misc.*;
import palidino76.rs2.player.*;
import palidino76.rs2.Engine;
import palidino76.rs2.player.Player;
import palidino76.rs2.EventManager.*;


public class PlayerCombat {
	public int CombatXPRate = 100;
    public void GiveRangeXP(Player p) {
	int playerHitDamage = getRandom(getRangedMaxhit());
      if(p.fightStyle == 7) {
   		p.addSkillXP(4 * playerHitDamage * CombatXPRate ,4);

      } else if(p.fightStyle == 8) {
  	 	p.addSkillXP((4 * playerHitDamage * CombatXPRate)/2 ,4);
  		p.addSkillXP((4 * playerHitDamage * CombatXPRate)/2 ,1);
      }
      p.addSkillXP((4 * playerHitDamage * CombatXPRate)/3 ,3);
	  p.addSkillXP((4 * playerHitDamage * CombatXPRate),4);
   }
	public int enemyIndex;

	Player p;

	/**
	 * Constructor
	 */
	public PlayerCombat(Player p) {
		this.p = p;
	}

	/**
	 * The pvn system.
	 */
	public void attackNpc() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null || n.isDead || n.currentHP <= 0) {
			p.attackNpc = 0;
			p.requestFaceTo(65535);
			p.resetAttack();
			return;
		}
		int randomVariable = 0;
		int npcCoord = 0;
		int npcSize = 0;
		if (n.npcType == 6203 || n.npcType == 6208 || n.npcType == 6204) {
			if (!p.zammyChamber())
				p.frames.sendMessage(p, "I can't reach that!");
			if (!p.zammyChamber())
				p.resetAttack();
			if (!p.zammyChamber())
				return;
		}
        	if(n.size > 1)
            		if(p.absX < npcSize && p.absY > npcCoord) {
                		if(p.absY - npcCoord > 1 && n.size >= 3)
                    			randomVariable += n.size;
                		else
                    			randomVariable += n.size / 2;
            		} else
            			if(p.absX > npcSize && p.absY > npcCoord) {
                			if(p.absY - npcCoord > 1 && n.size >= 3)
                   				randomVariable += n.size;
                			else
                    				randomVariable += n.size / 2;
            			} else
            				if(p.absX > npcSize && p.absY <= npcCoord)
                				if(p.absX - npcSize > 1 && n.size >= 3)
                    					randomVariable += n.size / 2;
                				else
                    					randomVariable += n.size / 2 - 1;
		byte byte0 = 60;

		if (usingRange()) {
			if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) > 7)
				return;
			if (!p.correctDistance(npcSize, npcCoord, n.absX, n.absY, 7)) {
				byte0 = 70;
				Server.engine.playerMovement.resetWalkingQueue(p);
			}
		} else {
			if (n.npcType == 1158 || n.npcType == 1160 || n.npcType == 6203 || n.npcType == 6260) {
				if (!p.correctDistance(npcSize, npcCoord, n.absX, n.absY, 1)) {
					byte0 = 70;
					Server.engine.playerMovement.resetWalkingQueue(p);
				}
			} else {
				if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) > 1) {
					return;
				}
			}
		}
		if (p.faceToReq != (p.attackNpc))
			p.requestFaceTo(p.attackNpc);
		if (usingRange())
			Server.engine.playerMovement.resetWalkingQueue(p);
		int casterX = p.absX;
		int casterY = p.absY;
       		int offsetX = (p.absX - n.absX) * -1;
        	int offsetY = (p.absY - n.absY) * -1;
		boolean isSpecWep = false;
		p.combatType = 2;
		if (p.atkDelay == 0) {
			if (p.usingSpecial) {
				switch (p.equipment[3]) {

					case 861:
						p.nextGraphicDelay = 1;
						p.damageSpecDelay = 3;
						p.enableSpecDamage = true;
						p.requestGFX(250, 100);
						p.requestAnim(1074, 0);
						p.frames.addProjectile3(p, casterY, casterX, offsetY, offsetX, 50, 75, 249, 46, 31, p.attackNpc, true);
						p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 95, 249, 46, 31, p.attackNpc, true);
						p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 100, 249, 46, 31, p.attackNpc, true);
						isSpecWep = true;
					break;

					case 11235:
						/**
						 * Dark Bow
						 */
						p.requestAnim(426, 0);
						p.damageSpecDelay = 3;
						p.enableSpecDamage = true;
						if (p.equipment[13] == 11212) {
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 90, 1099, 46, 31, p.attackNpc, true);
							p.frames.addProjectile2(p, casterY, casterX, offsetY, offsetX, 50, 120, 1099, 46, 31, p.attackNpc, true);
							p.frames.playSound(p, 3731, 1, 0);
						} else {
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 90, 1102, 46, 31, p.attackNpc, true);
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 120, 1102, 46, 31, p.attackNpc, true);
							p.frames.playSound(p, 3731, 1, 0);
						}
						isSpecWep = true;
					break;

					case 3204:
						/**
						 * Dragon halberd
						 */
            					char c = '\u0BAB';
            					char c11 = '\u0CDD';
            					if(p.absX > c)
                					//p.requestGFX(284, 100);
							p.frames.createStaticGraphic(p, 284, p.absX+1, p.absY);
						else
							//p.requestGFX(285, 100);
							p.frames.createStaticGraphic(p, 285, p.absX, p.absY);
						if (p.absY > c11)
							//p.requestGFX(282, 100);
							p.frames.createStaticGraphic(p, 282, p.absX, p.absY);
						else
							//p.requestGFX(283, 100);
							p.frames.createStaticGraphic(p, 283, p.absX, p.absY);
						p.requestAnim(1203, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 11694:
						/**
						 * Armadyl Godsword
						 */
						p.frames.playSound(p, 3865, 1, 25);
						p.requestGFX(1222, 0);
						p.requestAnim(7074, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;


					case 11700:
						/**
						 * Zamorak Godsword
						 */
						Player p2 = Engine.players[enemyIndex];
						p.frames.playSound(p, 3834, 1, 0);
                 						p2.requestGFX(369, 1);
						p.requestGFX(1221, 0);
						p.requestAnim(7070, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 8809:
						/**
						 * Statius Warhammer
						 */
						p.frames.playSound(p, 3865, 1, 25);
						p.requestGFX(1840, 0);
						p.requestAnim(10505, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 10887:
						/**
						 * BarrelChest Anchor
						 */
						p.requestGFX(1027, 0);
						p.requestAnim(5870, 0);
						p.damageSpecDelay = 2;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;
	
					case 11730:
						/**
						 * Saradomin sword
						 */
						p.requestAnim(7072, 0);
						n.requestGFX(1224, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;


					case 11696:
						/**
						 * Bandos Godsword
						 */
						p.frames.playSound(p, 3834, 1, 0);
						p.requestGFX(1223, 0);
						p.requestAnim(7073, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 11698:
						/**
						 * Saradomin Godsword
						 */
						p.frames.playSound(p, 3834, 1, 0);
						p.requestGFX(1220, 0);
						p.requestAnim(7071, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 5698:
						p.frames.playSound(p, 2537, 1, 0);
						p.requestGFX(252, 100);
						p.requestAnim(0x426, 0);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;

					case 3101:
						p.frames.playSound(p, 2537, 1, 0);
            						p.requestAnim(2068, 0);
            						p.requestGFX(274, 100);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
						p.frames.playSound(p, 2537, 1, 0);
            						p.requestAnim(2068, 0);
            						p.requestGFX(274, 100);
						p.damageSpecDelay = 1;
						p.enableSpecDamage = true;
						isSpecWep = true;
					break;
				}
				p.usingSpecial = false;
				p.specAmount -= getSpecAmount();
				setAtkDelay(getCombatDelay());
				p.checkAmount();
				p.frames.setConfig(p, 301, 0);
				if (isSpecWep) {
					return;
				}
			}
			n.randomWalk = false;
			if (!usingRange()) {
				appendNpcDamageMelee();
				setNpcDamageDelay(1);
				setEnableDamageNpc(true);
			} else {
				p.requestGFX(getPullback(), 100);
				setNpcDamageDelay(getRangeDamageDelay());
				GiveRangeXP(p);
				setEnableDamageNpc(true);
				if (p.equipment[3] == 4734) {
					setAtkDelay(getCombatDelay());
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, getProjSpeed(), getProjectile(), 38, 33, p.attackNpc, true);
				} else if (p.equipment[3] == 9185) {
					setAtkDelay(getCombatDelay());
					p.frames.addProjectile4(p, casterY, casterX, offsetY, offsetX, 50, getProjSpeed(), getProjectile(), 35, 35, p.attackNpc, true);
				} else {
					setAtkDelay(getCombatDelay());
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, getProjSpeed(), getProjectile(), 46, 33, p.attackNpc, true);
				}
			}
			p.requestAnim(getCombatAnim(), 0);
			setAtkDelay(getCombatDelay());
		}
	}

	public void attackPlayer() {
		Player en = Server.engine.players[p.enemyIndex];
		if (p == null || en == null || p.isDead || en.isDead) {
			p.requestFaceTo(65535);
			p.resetAttack();
			return;
		}
		int casterX = p.absX;
		int casterY = p.absY;
        	int offsetX = (p.absX - en.absX) * -1;
        	int offsetY = (p.absY - en.absY) * -1;
		PlayerMethods pm = new PlayerMethods(p);

		if (!isInWildRange(p) && !p.duelFight() && !p.AtPits()) {
		    if (Misc.getDistance(p.absX, p.absY, en.absX, en.absY) <= getDistancePk()) {
	   		p.frames.sendMessage(p, "Your level difference is too great!");
	   		p.frames.sendMessage(p, "You need to move further into the Wilderness.");
			p.resetAttack();
	   		return;
		    }
		if (p.equipment[1] == 4041 && en.equipment[1] == 4041) {
	   		p.frames.sendMessage(p, "You cannot attack a player that is on your team.");
			p.resetAttack();
	   		return;
		    }
		if (p.equipment[1] == 4042 && en.equipment[1] == 4042) {
			p.frames.sendMessage(p, "You cannot attack a player that is on your team.");
			p.resetAttack();
			return;
		}
		if(p.AtPits() && p.GameStarted == false)
{
p.frames.sendMessage(p,p.PitGame+" till game begins.");
 p.resetAttack();
return;
}
		}
		
		/*if(p.inBounty) {
		Player p2 = Engine.players[enemyIndex];
	    Player p3 = Engine.players[p2.attackedBy];
	    if(p2.attackedBy > 0 && p2.playerId != p.bhTarget && p2.bhTarget != p.playerId &&
	       p2.attackedBy != p.playerId && p2.attackedBy != p2.bhTarget &&
	       p3.bhTarget != p2.playerId) {
		   p.resetAttack();
		p.frames.sendMessage(p, "This player is already in combat with another person.");
		p.enemyId = 0;
	        return;
	    }
	}*/

		if (p.inEdgePk() && en.inEdgePk() || !p.multiZone() && !en.multiZone() || !p.AtPits()) {
		    if (Misc.getDistance(p.absX, p.absY, en.absX, en.absY) <= getDistancePk()) {
			if (p.combatWith != en.playerId && p.combatWith != 0) {
				p.requestFaceTo(p.enemyIndex + 32768);
				p.requestFaceTo(65535);
				p.resetAttack();
				p.frames.sendMessage(p, "You are already in combat.");
				return;
			}
			if (en.combatWith != p.playerId && en.combatWith != 0) {
				p.requestFaceTo(p.enemyIndex + 32768);
				p.requestFaceTo(65535);
				p.resetAttack();
				p.frames.sendMessage(p, "That player is already in combat.");
				return;
			}
		    }
		}

		if (p.faceToReq != (p.enemyIndex + 32768)) {
			p.requestFaceTo(p.enemyIndex + 32768);
		}
		if (usingRange()) {
			Server.engine.playerMovement.resetWalkingQueue(p);
		}		
		appendFollowing(p);

		if (Misc.getDistance(p.absX, p.absY, en.absX, en.absY) > getDistancePk()) {
			return;
		}

		p.combatType = 1;
		boolean isSpecWep = false;

            if (p.wildernessArea(en.absX, en.absY) && p.wildernessArea(p.absX, p.absY)) {
		if (p.usingSpecial) {
		    if (p.equipment[3] == 4153) {
			switch (p.equipment[3]) {
					case 4153:
						/**
						 * Granite Maul
						 */
						p.requestAnim(1667, 0);
						p.requestGFX(340, 100);
						pm.setSpecDelay(1);
						isSpecWep = true;
						p.frames.playSound(p, 2715, 1, 0);
						p.frames.playSound(en, 2715, 1, 0);
						break;
			}
			p.usingSpecial = false;
			p.specAmount -= getSpecAmount();
			pm.setCombatDelay(getCombatDelay());
			p.checkAmount();
			p.frames.setConfig(p, 301, 0);

			if (isSpecWep) {
				p.equipSpecDelay = getSpecialDelayEquiping();
				return;
			}
		    }
		}

		if (p.combatDelay <= 0) {
			if (p.usingSpecial) {
				switch (p.equipment[3]) {

					case 11235:
						/**
						 * Dark bow
						 */
						p.requestGFX(getPullback(), 98);
						p.requestGFX(getPullback(), 102);
						p.requestAnim(426, 0);
						pm.setSpecDelay(4);
						pm.setSpecDelay2(5);
						dBowSpec = true;
						if (p.equipment[13] == 11212) {
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 90, 1099, 46, 31, en.playerId, true);
							p.frames.addProjectile2(p, casterY, casterX, offsetY, offsetX, 50, 120, 1099, 46, 31, en.playerId, true);
							p.frames.playSound(en, 3731, 1, 0);
							p.frames.playSound(p, 3731, 1, 0);
						} else {
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 90, 1102, 46, 31, en.playerId, true);
							p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 120, 1102, 46, 31, en.playerId, true);
							p.frames.playSound(en, 3731, 1, 0);
							p.frames.playSound(p, 3731, 1, 0);
						}
						isSpecWep = true;
					break;

					case 861:
						p.frames.playSound(p, 2545, 1, 0);
						p.frames.playSound(en, 2545, 1, 0);
						pm.setSpecDelay(3);
						pm.setSpecDelay2(4);
						p.msbDelay = 1;
						p.combatDelay = 5;
						p.requestGFX(256, 100);
						p.requestAnim(1074, 0);
						p.frames.addProjectile3(p, casterY, casterX, offsetY, offsetX, 50, 75, 249, 46, 31, en.playerId, true);
						p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 95, 249, 46, 31, en.playerId, true);
						isSpecWep = true;
					break;

					case 3204:
						/**
						 * Dragon halberd
						 */
						p.frames.createStaticGraphic(p, 282, p.absX+1, p.absY);
						p.requestAnim(1203, 0);
						pm.setSpecDelay(1);
						pm.setSpecDelay2(2);
						isSpecWep = true;
					break;

					case 11730:
						/**
						 * Saradomin Sword
						 */
						p.requestGFX(1224, 0);
						p.requestAnim(7072, 0);
						pm.setSpecDelay(3);
						pm.setSpecDelay2(3);
						isSpecWep = true;
					break;

					case 11694:
						/**
						 * Armadyl Godsword
						 */
						p.frames.playSound(p, 3865, 1, 25);
						p.frames.playSound(en, 3865, 1, 25);
						p.requestGFX(1222, 0);
						p.requestAnim(7074, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;


					case 8809:
						/**
						 * Statius Warhammer
						 */
						p.frames.playSound(p, 3865, 1, 25);
						p.frames.playSound(en, 3865, 1, 25);
						p.requestGFX(1840, 0);
						p.requestAnim(10505, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 11696:
						/**
						 * Bandos Godsword
						 */
						p.frames.playSound(p, 3834, 1, 0);
						p.frames.playSound(en, 3834, 1, 0);
						p.requestGFX(1223, 0);
						p.requestAnim(7073, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;
					
					case 11698:
						/**
						 * Saradomin Godsword
						 */
						p.requestGFX(1220, 0);
						p.requestAnim(7071, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 11700:
						/**
						 * Zamorak Godsword
						 */
						Player p2 = Engine.players[p.enemyIndex];
                 						p2.requestGFX(369, 1);						
						p.requestGFX(1221, 0);
						p.requestAnim(7070, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 4587:
						/**
						 * Dragon Scimitar
						 */
						p.requestGFX(347, 100);
						p.requestAnim(1872, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 7158:
						/**
						 * Dragon 2Handed sword
						 */
						p.requestGFX(559, 0);
						p.requestAnim(3157, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 1434:
						/**
						 * Dragon Mace
						 */
						p.frames.playSound(p, 2541, 1, 0);
						p.frames.playSound(en, 2541, 1, 0);
						p.requestGFX(251, 100);
						p.requestAnim(1060, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 1305:
						/**
						 * Dragon Longsword
						 */
						p.frames.playSound(p, 2529, 1, 0);
						p.frames.playSound(en, 2529, 1, 0);
						p.requestGFX(248, 100);
						p.requestAnim(1058, 0);
						pm.setSpecDelay(2);
						isSpecWep = true;
					break;

					case 5698:
						/**
						 * Dragon Dagger (S)
						 */
						p.frames.playSound(p, 2537, 1, 0);
						p.frames.playSound(en, 2537, 1, 0);
						p.requestGFX(252, 100);
						p.requestAnim(0x426, 0);
						isSpecWep = true;
						pm.setSpecDelay2(1);
						pm.setSpecDelay(1);
					break;
					case 3101:
						/**
						 * Dragon Claws
						 */
						p.frames.playSound(p, 2537, 1, 0);
						p.frames.playSound(en, 2537, 1, 0);
            						p.requestAnim(2068, 0);
            						p.requestGFX(274, 100);
						isSpecWep = true;
						pm.setSpecDelay3(1);
						pm.setSpecDelay2(1);
						pm.setSpecDelay(1);
					break;

					case 10887:
						/**
						 * Barrel chest anchor
						 */
						p.requestGFX(1027, 0);
						p.requestAnim(5870, 0);
						pm.setSpecDelay(4);
						isSpecWep = true;
					break;

					case 4151:
						/**
						 * Abyssal whip
						 */
						p.requestAnim(1658, 0);
						pm.setSpecDelay(2);
						p.frames.playSound(p, 2713, 1, 0);
						p.frames.playSound(en, 2713, 1, 0);
						isSpecWep = true;
					break;
				}
				p.usingSpecial = false;
				p.specAmount -= getSpecAmount();
				pm.setCombatDelay(getCombatDelay());
				p.checkAmount();
	    			en.cmbResetTimer = 8;
				en.combatWith = p.playerId;
				p.frames.setConfig(p, 301, 0);

				if (isSpecWep) {
					p.equipSpecDelay = getSpecialDelayEquiping();
					return;
				}
			}

				p.frames.playSoundInArea(p.absX, p.absY, 4,  getWepSound(), 1, 0);
	    			en.cmbResetTimer = 10;
				en.combatWith = p.playerId;
				en.enemyIndex = p.playerId;

		if (p.wildernessArea(en.absX, en.absY) && p.wildernessArea(p.absX, p.absY) || p.duelFight() && en.duelFight()) {
				en.combatWith = p.playerId;
			if (!p.duelFight() && !p.AtPits() && !p.AtCastleWars() && !p.inBounty) {
				if (!p.isSkulled && en.enemyIndex != p.playerId) {
					p.headIconSkull = 0;
					p.skullVanishDelay = 1200;
					p.isSkulled = true;
					p.appearanceUpdateReq = true;
					p.updateReq = true;
				}
			}
		}

			if (!usingRange()) {
				p.requestAnim(getCombatAnim(), 0);
				pm.setDamageDelay(2);
				pm.isGonnaDamage(true);
				pm.setCombatDelay(getCombatDelay());
			} else {

			    /*if (p.equipment[3] != 9185 && p.equipment[3] != 4734 && p.equipment[3] != 868) {
					p.frames.playSound(p, 2693, 1, 0);
					p.frames.playSound(en, 2693, 1, 0);
				}*/

				p.requestGFX(getPullback(), 100);
				p.requestAnim(getCombatAnim(), 0);////
				GiveRangeXP(p);
			    if (p.equipment[3] != 11235 || p.equipment[3] != 868) {
				pm.setRangeDamageDelay(getRangeDamageDelayPk());
			    }
				pm.setRangeDamage(true);
				p.combatDelay = getCombatDelay();

				if (p.equipment[13] == 9244 && p.equipment[3] == 9185) {
				    if (getRandom(6) == 6) {
					crossBowDragon = true;
				    } else {
					crossBowDragon = false;
				    }
				}
				if (p.equipment[13] != 9244 || p.equipment[3] != 9185) {
					crossBowDragon = false;
				}
				if (crossBowDragon) {
					p.frames.playSound(p, 2915, 1, 0);
					p.frames.playSound(en, 2915, 1, 0);
					en.requestGFX(756, 60);
				}
				if (p.equipment[3] == 4734) {
					setAtkDelay(getCombatDelay());
					p.combatDelay = getCombatDelay();
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 70, getProjectile(), 38, 30, en.playerId, true);
				} else if (p.equipment[3] == 868) {
					pm.setRangeDamageDelay(2);
					p.requestGFX(225, 100);
					setAtkDelay(getCombatDelay());
					p.frames.addProjectile5(p, casterY, casterX, offsetY, offsetX, 50, 70, 218, 38, 30, en.playerId, true);
				} else if (usingDarts()) {
					pm.setRangeDamageDelay(2);
					p.requestGFX(getDartDrawback(), 100);
					setAtkDelay(getCombatDelay());
					p.frames.addProjectile5(p, casterY, casterX, offsetY, offsetX, 50, 60, getDartGFX(), 38, 30, en.playerId, true);
				} else if (p.equipment[3] == 9185) {
					setAtkDelay(getCombatDelay());
					p.combatDelay = getCombatDelay();
					p.frames.addProjectile4(p, casterY, casterX, offsetY, offsetX, 50, 70, getProjectile(), 36, 36, en.playerId, true);
				} else if (p.equipment[3] == 4214) {
					setAtkDelay(getCombatDelay());
					p.combatDelay = getCombatDelay();
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 70, 249, 46, 31, en.playerId, true);
				} else if (p.equipment[3] == 11235) {
					setAtkDelay(getCombatDelay());
					pm.setRangeDamageDelay(2);
					pm.setRangeDamageDelay(4);
					p.combatDelay = getCombatDelay();
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 90, getProjectile(), 46, 31, en.playerId, true);
					p.frames.addProjectile2(p, casterY, casterX, offsetY, offsetX, 50, 120, getProjectile(), 46, 31, en.playerId, true);
				} else {
					setAtkDelay(getCombatDelay());
					p.combatDelay = getCombatDelay();
					p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 80, getProjectile(), 46, 31, +en.playerId - 1, true);
				}
			    if (p.equipment[3] == 861 && p.usingSpecial) {
				pm.setCombatDelay(5);
			    } else {
				pm.setCombatDelay(getCombatDelay());
			    }
		      	}	
		    }	
	     	}
	}

	public void appendFollowing(Player p) {
		Player en = Server.engine.players[p.enemyIndex];

        	if (p.wildernessArea(en.absX, en.absY) && p.wildernessArea(p.absX, p.absY)) {
	    		if (usingRange() && Misc.getDistance(p.absX, p.absY, en.absX, en.absY) < 8) {
				return;
	    		}
	    		if (p.freezeDelay == 0) {
				int n;
				n = en.absY - p.absY; // This will get updated in process.

				if ((en.absX - p.absX) <= (n * (-1)) && (en.absX - p.absX) >= (n - 1)) {
		    			if (n < 0) {
						p.WalkingTo(en.absX, en.absY + 1);
		   			}
		    			if (n > 0) {
						p.WalkingTo(en.absX, en.absY - 1);
		    			}
				} else if ((en.absX - p.absX) > 0) {
					p.WalkingTo(en.absX - 1, en.absY);
				} else if ((en.absX - p.absX) < 0) {
					p.WalkingTo(en.absX + 1, en.absY);
				}
				if (((en.absX - p.absX) == 0) && (n < 0)) {
					p.WalkingTo(en.absX, en.absY + 1);
				}
				if (((en.absX - p.absX) == 0) && (n >= 0)) {
					p.WalkingTo(en.absX, en.absY - 1);
				}
				if (en.absX - p.absX > 12 || p.absX - en.absX > 12 ||en.absY - p.absY > 12 || p.absY - en.absY > 12) {
					p.WalkingTo(p.absX, p.absY); // Reset walking if the other player is further then 12 squares (To prevent the following if p2 teleports away)
				}
	   		}
		} else {
			p.requestFaceTo(65535);
			p.resetAttack();
		}
	}

	public int getDartGFX() {
		int j = p.equipment[3];

		if (j == 806) {
			return 226;
		}
		if (j == 807) {
			return 227;
		}
		if (j == 808) {
			return 228;
		}
		if (j == 809) {
			return 229;
		}
		if (j == 810) {
			return 230;
		}
		if (j == 811) {
			return 231;
		}
		if (j == 11230) {
			return 1122;
		}
		return 0;
	}

	public int getDartDrawback() {
		int j = p.equipment[3];

		if (j == 806) {
			return 232;
		}
		if (j == 807) {
			return 233;
		}
		if (j == 808) {
			return 234;
		}
		if (j == 809) {
			return 235;
		}
		if (j == 810) {
			return 236;
		}
		if (j == 811) {
			return 237;
		}
		if (j == 11230) {
			return 1123;
		}
		return 0;
	}

	public int wildLvl(Player p) {
		return (p.absY - 3520) / 8+1;
    	}

	public boolean isInWildRange(Player p) {
		Player p2 = Engine.players[p.enemyIndex]; 

	    if (p.combatLevel > p2.combatLevel) {
	      	if (p.combatLevel - p2.combatLevel <= wildLvl(p2)) {
			return true;
	      	}
	    } else if (p.combatLevel < p2.combatLevel) {
	   	if (p2.combatLevel - p.combatLevel <= wildLvl(p2)) {
			return true;
	   	}
	    } else if (p.combatLevel == p2.combatLevel) {
			return true;
            }
    			return false;
    	}

	public void addNextAttack() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null || n.isDead || n.currentHP <= 0) {
			p.attackNpc = 0;
			p.requestFaceTo(65535);
			p.resetAttack();
			return;
		}
		int casterX = p.absX;
		int casterY = p.absY;
       		int offsetX = (p.absX - n.absX) * -1;
        	int offsetY = (p.absY - n.absY) * -1;
		PlayerMethods pm = new PlayerMethods(p);
		p.nextDamageDelay = 3;
		p.requestGFX(250, 100);
		p.frames.addProjectile(p, casterY, casterX, offsetY, offsetX, 50, 100, 249, 46, 31, n.npcId, true);
		p.nextGraphicDelay = -1;
	}

	/**
	 * Magic shortbow second damage.
	 */
	public void addNextDamage() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null || n.isDead || n.currentHP <= 0) {
			p.attackNpc = 0;
			p.requestFaceTo(65535);
			p.resetAttack();
			return;
		}
		if (p.nextDamageDelay == 0) {
			n.appendHit(getRandom(getMaxhit()), 0);
		}
		p.nextDamageDelay = -1;
	}

	int getSpecialDelayEquiping() {
		switch (p.equipment[3]) {

			case 10887:
				return 0;
			default:
				return 0;
		}
	}

	int getPullback() {
		if (p.equipment[13] == 868) {
			return 225;
		}
		if (p.equipment[13] == 882) {
			return 19;
		}
		if (p.equipment[13] == 884) {
			return 18;
		}
		if (p.equipment[13] == 886) {
			return 20;
		}
		if (p.equipment[13] == 888) {
			return 21;
		}
		if (p.equipment[13] == 890) {
			return 22;
		}
		if (p.equipment[13] == 892) {
			return 23;
		}
		if (p.equipment[13] == 11212 && p.equipment[3] == 11235) {
			return 1111;
		}
		if (p.equipment[13] == 892 || p.equipment[13] == 890  || p.equipment[13] == 888  || p.equipment[13] == 886  || p.equipment[13] == 884  || p.equipment[13] == 882 && p.equipment[3] == 11235) {
			return 1109;
		}
		if (p.equipment[13] == 4214) {
			return 249;
		}
		if (p.equipment[13] == 9706) {
			return 25;
		}
		if (p.equipment[13] == -1 && p.equipment[3] == 4214 || p.equipment[13] >= -1 && p.equipment[3] == 4214) {
			return 250;
		}
	return -1;
	}

	int getSpecAmount() {
		if (p.equipment[3] == 861) {
			return 600;
		}
		if (p.equipment[3] == 4153) {
			return 500;
		}
		if (p.equipment[3] == 11730) {
			return 1000;
		}
		if (p.equipment[3] == 11235) {
			return 600;
		}
		if (p.equipment[3] == 4587) {
			return 500;	
		}
		if (p.equipment[3] == 1305) {
			return 250;
		}
		if (p.equipment[3] == 1434) {
			return 250;
		}
		if (p.equipment[3] == 5698) {
			return 250;
		}
		if (p.equipment[3] == 11694) {
			return 500;
		}		
		if (p.equipment[3] == 8809) {
			return 500;
		}
		if (p.equipment[3] == 3101) {
			return 250;
		}
		if (p.equipment[3] == 11696) {
			return 1000;
		}
		if (p.equipment[3] == 11698) {
			return 500;
		}
		if (p.equipment[3] == 11700) {
			return 500;
		}
		if (p.equipment[3] == 4151) {
			return 500;
		}
		if (p.equipment[3] == 4153) {
			return 500;
		}
		if (p.equipment[3] == 3204) {
			return 500;
		}
		if (p.equipment[3] == 10887) {
			return 500;
		}
	return 0;
	}

	int getDistance() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null)
			return 1;
		if (usingRange())
			return 7;
		else
			return 1;
	}

	int getDistancePk() {
		if (p == null) {
			return 1;
		}
		if (usingRange()) {
			return 9;
		} else if (!usingRange() && p.freezeDelay > 0) {
			return 1;
		} else if (!usingRange() && p.freezeDelay <= 0) {
			return 3;
		} else {
			return 1;
		}
	}

    public int meleeDef() {
        int i = p.equipmentBonus[bestmeleeDef()];
        int j = p.skillLvl[1];
        int k = p.getLevelForXP(1);
        int l = 0;
	
	if (p.skillLvl[1] <= 10) {
	    j += (int)((double)j + (double)k + (double)k);
	}
        if (p.thickSkin) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (p.rockSkin) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (p.steelSkin) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (p.chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);

        } else if (p.pietyPrayer) {
            j = (int)((double)j + (double)k * 0.25D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D));
        return l;
    }

    public int rangeDef() {
        int i = p.equipmentBonus[9];
        int j = p.skillLvl[1];
        int k = p.getLevelForXP(1);
        int l = 0;

        if (p.thickSkin) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (p.rockSkin) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (p.steelSkin) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (p.chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);

        } else if (p.pietyPrayer) {
            j = (int)((double)j + (double)k * 0.25D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D));
        return l;
    }

    public int rangeAtk() {
        int i = p.equipmentBonus[4];
        int j = p.skillLvl[4];
        int k = p.getLevelForXP(4);
        int l = 0;

	if (p.eagleEyePrayer) {
		j = (int)((double)j + (double)k * 0.14999999999999999D);
	}
	if (usingDarts()) {
		j = (int)((double)j + (double)k * 0.20D);
	}

        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D) + Misc.random(8));
        return l;
    }

    public int meleeAtk() {
        int i = p.equipmentBonus[bestmeleeAtk()];
        int j = p.skillLvl[0];
        int k = p.getLevelForXP(0);
        int l = 0;

        if (p.clarity) {
            j = (int)((double)j + (double)k * 0.050000000000000003D);

        } else if (p.improvedReflex) {
            j = (int)((double)j + (double)k * 0.10000000000000001D);

        } else if (p.incredibleReflex) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (p.chilvaryPrayer) {
            j = (int)((double)j + (double)k * 0.14999999999999999D);

        } else if (p.pietyPrayer) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);

        } else if (p.equipment[3] == 11694) {
            j = (int)((double)j + (double)k * 0.20000000000000001D);
	}
        l += (int)((double)j + (double)j * 0.14999999999999999D + ((double)i + (double)i * 0.050000000000000003D) + Misc.random(5));
        return l;
    }

    public int bestmeleeAtk() {
        if(p.equipmentBonus[0] > p.equipmentBonus[1] && p.equipmentBonus[0] > p.equipmentBonus[2]) {
            return 0;
        }
        if(p.equipmentBonus[1] > p.equipmentBonus[0] && p.equipmentBonus[1] > p.equipmentBonus[2]) {
            return 1;
        }
        return p.equipmentBonus[2] <= p.equipmentBonus[1] || p.equipmentBonus[2] <= p.equipmentBonus[0] ? 0 : 2;
    }

    public int bestmeleeDef() {
        if(p.equipmentBonus[5] > p.equipmentBonus[6] && p.equipmentBonus[5] > p.equipmentBonus[7]) {
            return 6;
        }
        if(p.equipmentBonus[6] > p.equipmentBonus[5] && p.equipmentBonus[6] > p.equipmentBonus[7]) {
            return 7;
        }
        return p.equipmentBonus[7] <= p.equipmentBonus[5] || p.equipmentBonus[7] <= p.equipmentBonus[6] ? 5 : 7;
    }

    public int BestAttackBonus(Player p)
    {
        if(p.equipmentBonus[0] > p.equipmentBonus[1] && p.equipmentBonus[0] > p.equipmentBonus[2]) {
            return 0;
	}
        if(p.equipmentBonus[1] > p.equipmentBonus[0] && p.equipmentBonus[1] > p.equipmentBonus[2]) {
            return 1;
	}
	if(p.equipmentBonus[2] > p.equipmentBonus[1] ||  p.equipmentBonus[2] > p.equipmentBonus[0]) {
	    return 2;
	}
	return 1;
    }

    public boolean Defence(Player p) {
		int att_def =  BestAttackBonus(p);
		int BestAttack = p.equipmentBonus[BestAttackBonus(p)] + p.skillLvl[0] + Misc.random(25);
		int DefenceBonus = Engine.players[p.enemyIndex].equipmentBonus[att_def+5] + (Engine.players[p.enemyIndex].skillLvl[1]) ;
	if (p.fightStyle == 1) {
		BestAttack += Misc.random(5);
	}
        if ((Misc.random(BestAttack)) > Misc.random(DefenceBonus)) {
   		return true;
	}
   		return false;
    }

    /*public boolean rangedDefence(Player p) {
		int att_def =  BestAttackBonus(p);
		int RangedAttack = p.equipmentBonus[4] + p.skillLvl[4] + Misc.random(60);
		int DefenceBonus = Engine.players[p.enemyIndex].equipmentBonus[9] + (Engine.players[p.enemyIndex].skillLvl[1]) ;
        if ((Misc.random(RangedAttack)) > Misc.random(DefenceBonus)) {
   		return true;
	}
   		return false;
    }*/

    public boolean rangedDefence(Player p) {
		int att_def =  BestAttackBonus(p);
		int RangedAttack = rangeAtk() + Misc.random(60);
		int DefenceBonus = Engine.players[p.enemyIndex].rangeDef();
        if ((Misc.random(RangedAttack)) > Misc.random(DefenceBonus)) {
   		return true;
	}
   		return false;
    }

	boolean usingRange() {
		for (int i = 0; i < p.rangeBows.length; i++) {
			if (p.equipment[3] == p.rangeBows[i] || p.equipment[3] == 11235 || p.equipment[3] == 4734 || p.equipment[3] == 9705 || p.equipment[3] == 4214 || p.equipment[3] == 9185 || p.equipment[3] == 861 || p.equipment[3] == 868 || usingDarts()) {
				return true;
			}
		}
	return false;
	}

	boolean usingDarts() {
		for (int i = 806; i < 819; i++) {
			if (p.equipment[3] == i || p.equipment[3] == 11230) {
				return true;
			}
		}
		return false;
	}

	boolean hasArrows() {
		for (int i = 0; i < p.rangeArrows.length; i++) {
			if (p.equipment[13] == p.rangeArrows[i] || p.equipment[13] == 4740 && p.equipment[3] == 4734 || p.equipment[13] == 9706) {
				return true;
			}
		}
	return false;
	}

 	public int getRangeHit() {
		if (p == null) {	
			return 1;
		}
		double maxHit = 0;
		maxHit += 1.06 + (p.skillLvl[4] * 0.01228);
		maxHit += p.skillLvl[4] * 0.16;
		if (p.equipment[13] == 892) {
			maxHit *= 1.44;
		}
		if (p.equipment[3] == 4214) {
			maxHit *= 2.10;
		}
		if (p.equipment[3] == 9185 && p.equipment[13] == 9244) {
			maxHit *= 3.80;
		}
		if (p.equipment[3] == 9185 && p.equipment[13] == 9244) {
			maxHit *= 2.80;
		}
		if (p.equipment[3] == 9185 && p.equipment[13] == 9144) {
			maxHit *= 2.50;
		}
		else if (p.equipment[13] == 890) {
			maxHit *= 1.30;
		}
		else if (p.equipment[13] == 888) {
			maxHit += 1.24;
		}
		else if (p.equipment[13] == 886) {
			maxHit += 1.19;
		}
		else if (p.equipment[13] == 884) {
			maxHit += 1.08;
		}
		else if (p.equipment[13] == 882) {
			maxHit += 1.05;
		}
		return (int)Math.floor(maxHit);
	}

	public int getMaxhit() {
	Player p2 = Engine.players[p.enemyIndex];
       		if(p == null) {
            		return 1;
        	}
        	double maxHit = 0;
		if (!usingRange()) {
			maxHit += 1.06 + (p.skillLvl[2] * 0.00130);
			maxHit += p.skillLvl[2] * 0.16;
		} else {
			maxHit += 1.06 + (p.skillLvl[4] * 0.00090);
			maxHit += p.skillLvl[4] * 0.16;
		}
		if (p.equipment[3] == 5698) { /* DDS */
			maxHit *= 1.34;
		}
		if (p.equipment[3] == 3101) { /* D Claws */
			maxHit *= 2.34;
		}
		if (p.equipment[3] == 6528) { /* Obby Maul */
		    if (p.equipment[2] == 11128) {
			maxHit *= 2.50;
		    } else {
			maxHit *= 2.10;
		    }
		}
		if (p.equipment[3] == 11235) { /* Dark bow */
			if (p.equipment[13] == 11212) {
				if (p.fullVoidKnightRange()) {
					maxHit *= 1.90;
				} else if (p.equipment[4] == 4720 && p.equipment[7] == 4722 && p.equipment[0] == 4716) {
					maxHit *= 1.01;
				} else {
					maxHit *= 1.64;
				}
			} else {
				maxHit *= 1.26;
			}
		}
		if (p.equipment[3] == 4153) { /* Granite maul */
			maxHit *= 1.32;
		}
		if (p.equipment[3] == 1305) { /* Dragon longsword */
			maxHit *= 1.78;
		}
		if (p.equipment[3] == 3204) { /* Dragon halberd */
			maxHit *= 1.65;
		}
		if (p.equipment[3] == 10887) { /* Barrelchest Anchor */
			maxHit *= 1.84;
		}
		if (p.equipment[3] == 1434) { /* Dragon mace */
			maxHit *= 1.82;
		}
		if (p.equipment[3] == 11696) { /* Bandos Godsword */
			maxHit *= 3.0;
		}
		if (p.equipment[3] == 11694) { /* Armadyl Godsword */
				maxHit *= 3.92;
		}
		if (p.equipment[3] == 8809) { /* Statius Warhammer */
				maxHit *= 3.00;
		}
		if (p.equipment[3] == 3101) { /* D Claws */
				maxHit *= 2.34;
		}
		if (p.equipment[3] == 5698) { /* DDS */
				maxHit *= 1.34;
		}
		if (p.equipment[3] == 11698) { /* Saradomin Godsword */
			maxHit *= 2.70;
		}
		if (p.equipment[3] == 11700) { /* Zamorak Godsword */
			maxHit *= 2.90;
		}
		if (p.equipment[3] == 11730) { /* Saradomin Sword */
			maxHit *= 2.47;
		} else {
			maxHit *= 1.40;
		}
        	if(p.fullDharok()) {
            		maxHit += (p.getLevelForXP(3) - p.skillLvl[3]) / 2;
        	}
        	return (int)Math.floor(maxHit);
    	}

    	public int getMeleeMaxhit() {
		Player p2 = Engine.players[enemyIndex];
        	if(p == null) {
           		return 1;
        	}
        	double maxHit = 1.06 + (p.equipmentBonus[10] * p.skillLvl[2]) * 0.00178;
        	//double maxHit = (p.equipmentBonus[10] * p.skillLvl[2]) * 0.00178;

        	if (p.fullDharok()) {
            		maxHit += (int) Math.floor((p.getLevelForXP(3) - p.skillLvl[3]) / 2);
        	}
		if (p.burstOfStr) {
			maxHit += (p.skillLvl[2]) * 0.05;
		}
		if (p.superHumanStr) {
			maxHit += (p.skillLvl[2]) * 0.09;
		}
		if (p.ultimateStr) {
			maxHit += (p.skillLvl[2]) * 0.015;
		}
		if (p.chilvaryPrayer) {
			maxHit += (p.skillLvl[2]) * 0.018;
		}
		if (p.pietyPrayer) {
			maxHit += (p.skillLvl[2]) * 0.025;
		}
        	return (int)(maxHit += p.skillLvl[2] * 0.16);
    	}

	public int getRangedMaxhit() {
        	if(p == null)
            		return 1;
		int arrowId = p.equipment[13];
        	double maxHit = 0;
		maxHit += 1.06 + (p.skillLvl[4] * 0.00178);
		maxHit += p.skillLvl[4] * 0.16;

		if (p.equipment[3] == 11230) {
			maxHit *= 1.21;
		}
		switch (arrowId) {

			case 882:
			case 883:
				maxHit *= 1.012;
			break;

			case 884:
			case 885:
				maxHit *= 1.024;
			break;

			case 886:
			case 887:
				maxHit *= 1.094;
			break;

			case 888:
			case 889:
				maxHit *= 1.15;
			break;

			case 890:
			case 891:
				maxHit *= 1.2;
			break;

			case 892:
			case 893:
				maxHit *= 1.30;
			break;

			case 4740:
				maxHit *= 1.50;
			break;

			case 11212:
				if (!dBowSpec) {
					maxHit *= 1.2;
				} else {
					if (p.fullVoidKnightRange()) {
						maxHit *= 3.70;
					} else if (p.equipment[4] == 4720 && p.equipment[7] == 4722 && p.equipment[0] == 4716) {
						maxHit *= 1.41;
					} else {
						maxHit *= 3.41;
					}
				}
			break;

			case 9244:
				if (p.equipment[3] == 9185 && crossBowDragon) {
					maxHit *= 4.91;
				}
				if (p.equipment[3] == 9185 && !crossBowDragon) {
					maxHit *= 3.91;
				}
			break;

			default:
				maxHit *= 1.04;
			break;
		}

		switch (p.equipment[3]) {
			case 4214:
				if (p.equipment[13] >= -1) {
					maxHit *= 1.70;
				}
				break;
		}

        	return (int)Math.floor(maxHit);
	}

	public void appendRangeDamage() {
		try {
			Player en = Server.engine.players[p.enemyIndex];
			PlayerMethods pm = new PlayerMethods(p);
			int playerHitDamage = getRandom(getRangedMaxhit());

			if (p.rangeDmgDelay == 0) {
		    	    if (en.teleDelay <= 0) {
				  if (!rangedDefence(p)) {
						en.appendHit(0, 0);
				} else {
					if (en.rangedPrayer) {
						playerHitDamage -= playerHitDamage / 2;
					}
						en.appendHit(getRandom(playerHitDamage), 0);

					if (en.usingVeng) {
						p.appendHit((int)((playerHitDamage / 4) * 3), 0);
						en.requestForceChat("Taste Vengeance!");
						en.vengUseDelay = 0;
						en.usingVeng = false;
					}
					if (p.smitePrayer && en.skillLvl[5] > 0) {
						en.skillLvl[5] -= (int)(playerHitDamage / 4);
						en.frames.setSkillLvl(en, 5);
					}
					if (p.equipment[3] == 11235) {
						en.appendHit(getRandom(playerHitDamage), 0);
					}
				}

				pm.setRangeDamageDelay(-1);
				pm.setRangeDamage(false);
			    }
			}
		} catch (Exception e) {
			return;
		}
	}

	/**
	 * Checks for accuracy weapons. (Chances on hitting high)
	 */
	boolean hasAccuracy() {
		for (int i = 0; i < godSwords.length; i++) {
			if (p.equipment[3] == godSwords[i]) {
				return true;
			}
		}
	return false;
	}

	/**
	 * Special Damage dealing
	 */
	public void appendSpecDamage() {
		try {
			Player en = Server.engine.players[p.enemyIndex];
			PlayerMethods pm = new PlayerMethods(p);
			int playerHitDamage = getRandom(getMaxhit());
			int atk = Misc.random(p.meleeAtk());
			int def = Misc.random(en.meleeDef());

			if (p.specDelay == 0) {
		    	    if (en.teleDelay <= 0) {
				if (atk < def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (p.equipment[3] == 5698) {
						if (p.equipment[3] == 5698) {
							en.appendHit(0, 0);
						} else if (p.equipment[3] == 3204) {
							en.appendHit(getRandom(getMaxhit()), 0);
						}
						if (p.equipment[3] == 5698) {
							if (!en.isPoisoned) {
								en.isPoisoned = true;
								en.poisonDelay = 45;
								en.poisonHitCount = 0;
							}
						}
					}
				if (atk < def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (p.equipment[3] == 3101) {
						if (p.equipment[3] == 3101) {
							en.appendHit(0, 0);
						} else if (p.equipment[3] == 3204) {
							en.appendHit(getRandom(getMaxhit()), 0);
						}
						if (p.equipment[3] == 5698) {
							if (!en.isPoisoned) {
								en.isPoisoned = true;
								en.poisonDelay = 45;
								en.poisonHitCount = 0;
							}
						}
					}
				}
						en.appendHit(0, 0);

						if (p.equipment[3] == 4151) {
							en.requestGFX(341, 100);
						}
						if (p.equipment[3] == 11700) {
							en.requestGFX(369, 0);
						}
						if (p.equipment[3] == 11730) {
							p.frames.playSound(p, 3853, 1, 0);
							p.frames.playSound(en, 3853, 1, 0);
							en.requestGFX(1194, 0);
						}
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
				} else if (atk > def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (en.meleePrayer) {
						playerHitDamage -= playerHitDamage / 2;
					}
						en.appendHit(getRandom(playerHitDamage), 0);
					if (en.usingVeng) {
						p.appendHit((int)((playerHitDamage / 4) * 3), 0);
						en.requestForceChat("Taste Vengeance!");
						en.usingVeng = false;
					}
						if (p.equipment[3] == 4151) {
							en.requestGFX(341, 100);
						}
						if (p.equipment[3] == 11700) {
							en.requestGFX(369, 0);
						}
						if (p.equipment[3] == 11730) {
							p.frames.playSound(p, 3853, 1, 0);
							p.frames.playSound(en, 3853, 1, 0);
							en.requestGFX(1194, 0);
						}
						if (p.equipment[3] == 11235) {
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
							en.requestGFX(1100, 100);
						}
				} else if (p.equipment[3] == 11235 || p.equipment[3] == 861) {
					if (!rangedDefence(p)) {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (p.equipment[3] == 861) {
							en.appendHit(0, 0);
						}
						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + (getRandom(20)), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15)), 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + (getRandom(20)), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15)), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					} else {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (en.usingVeng) {
							p.appendHit((int)((playerHitDamage / 4) * 3), 0);
							en.requestForceChat("Taste Vengeance!");
							en.usingVeng = false;
						}
						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit((8 + getRandom(getMaxhit())) - 8, 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + getRandom(getMaxhit()) - 5, 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + (getRandom(getMaxhit()) / 2), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					}
				}
				if (en.equipment[5] != -1) {
					en.requestAnim(en.getBlockAnim(), 0);
				} else {
					en.requestAnim(en.getBlockAnim1(), 0);
				}

				pm.setSpecDelay(-1);
				return;
			    }
			}
		} catch (Exception e) {
			return;
		}
	}

	/**
	 * Special Damage dealing
	 */
	public void appendSpecDamage2() {
		try {
			Player en = Server.engine.players[p.enemyIndex];
			PlayerMethods pm = new PlayerMethods(p);
			int playerHitDamage = getRandom(getMaxhit());
			int atk = Misc.random(p.meleeAtk());
			int def = Misc.random(en.meleeDef());

			if (p.specDelay2 == 0) {
		    	    if (en.teleDelay <= 0) {
				if (atk < def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
						en.appendHit(0, 0);

				} else if (atk > def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (en.meleePrayer) {
						playerHitDamage -= playerHitDamage / 2;
					}
						en.appendHit(getRandom(playerHitDamage), 0);

						if (en.usingVeng) {
						    if (playerHitDamage > 2) {
							p.appendHit((int)((playerHitDamage / 4) * 3), 0);
							en.requestForceChat("Taste Vengeance!");
							en.usingVeng = false;
						    } else {
							p.appendHit(playerHitDamage, 0);
						    }
						}
						if (p.smitePrayer && en.skillLvl[5] > 0) {
							en.skillLvl[5] -= (int)(playerHitDamage / 4);
							en.frames.setSkillLvl(en, 5);
						}
						if (p.equipment[3] == 4151) {
							en.requestGFX(341, 100);
						}
						if (p.equipment[3] == 11700) {
							en.requestGFX(369, 0);
						}
						if (p.equipment[3] == 11730) {
							p.frames.playSound(p, 3853, 1, 0);
							p.frames.playSound(en, 3853, 1, 0);
							en.requestGFX(1194, 0);
						}
						if (p.equipment[3] == 11235) {
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
							en.requestGFX(1100, 100);
						}
				} else if (p.equipment[3] == 11235 || p.equipment[3] == 861) {
					if (!rangedDefence(p)) {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (p.equipment[3] == 861) {
							en.appendHit(0, 0);
						}
						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + getRandom(20), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + getRandom(20), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					} else {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (en.usingVeng) {
							p.appendHit((int)((playerHitDamage / 4) * 3), 0);
							en.requestForceChat("Taste Vengeance!");
							en.usingVeng = false;
						}

						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit((8 + getRandom(getMaxhit())) - 8, 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + getRandom(getMaxhit()) - 5, 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + (getRandom(getMaxhit()) / 2), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					}
				}
				dBowSpec = false;

				if (en.equipment[5] != -1 && en.equipment[3] != 5698) {
					en.requestAnim(en.getBlockAnim(), 0);
				} else {
				    if (en.equipment[3] != 5698) {
					en.requestAnim(en.getBlockAnim1(), 0);
				    }
				}

				pm.setSpecDelay2(-1);
				return;
			    }
			}
		} catch (Exception e) {
			return;
		}
	}

	public void appendSpecDamage3() {
		try {
			Player en = Server.engine.players[p.enemyIndex];
			PlayerMethods pm = new PlayerMethods(p);
			int playerHitDamage = getRandom(getMaxhit());
			int atk = Misc.random(p.meleeAtk());
			int def = Misc.random(en.meleeDef());

			if (p.specDelay3 == 0) {
		    	    if (en.teleDelay <= 0) {
				if (atk < def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (p.equipment[3] == 3101) {
						if (p.equipment[3] == 3101) {
							en.appendHit(0, 0);
						} else if (p.equipment[3] == 3204) {
							en.appendHit(getRandom(getMaxhit()), 0);
						}
						if (p.equipment[3] == 5698) {
							if (!en.isPoisoned) {
								en.isPoisoned = true;
								en.poisonDelay = 45;
								en.poisonHitCount = 0;
							}
						}
					}
						en.appendHit(0, 0);

				} else if (atk > def && p.equipment[3] != 11235 && p.equipment[3] != 861) {
					if (en.meleePrayer) {
						playerHitDamage -= playerHitDamage / 2;
					}
						en.appendHit(getRandom(playerHitDamage), 0);

						if (en.usingVeng) {
						    if (playerHitDamage > 2) {
							p.appendHit((int)((playerHitDamage / 4) * 3), 0);
							en.requestForceChat("Taste Vengeance!");
							en.usingVeng = false;
						    } else {
							p.appendHit(playerHitDamage, 0);
						    }
						}
						if (p.smitePrayer && en.skillLvl[5] > 0) {
							en.skillLvl[5] -= (int)(playerHitDamage / 4);
							en.frames.setSkillLvl(en, 5);
						}
						if (p.equipment[3] == 4151) {
							en.requestGFX(341, 100);
						}
						if (p.equipment[3] == 11700) {
							en.requestGFX(369, 0);
						}
						if (p.equipment[3] == 11730) {
							p.frames.playSound(p, 3853, 1, 0);
							p.frames.playSound(en, 3853, 1, 0);
							en.requestGFX(1194, 0);
						}
						if (p.equipment[3] == 11235) {
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
							en.requestGFX(1100, 100);
						}
				} else if (p.equipment[3] == 11235 || p.equipment[3] == 861) {
					if (!rangedDefence(p)) {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (p.equipment[3] == 861) {
							en.appendHit(0, 0);
						}
						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + getRandom(20), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + getRandom(20), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					} else {
						if (p.equipment[3] == 11235) {
							en.requestGFX(1100, 100);
							p.frames.playSound(p, 3737, 1, 0);
							p.frames.playSound(en, 3737, 1, 0);
						}
						if (en.usingVeng) {
							p.appendHit((int)((playerHitDamage / 4) * 3), 0);
							en.requestForceChat("Taste Vengeance!");
							en.usingVeng = false;
						}

						if (p.equipment[3] == 11235) {
						    if (!en.rangedPrayer) {
							if (p.equipment[13] == 11212) {
								en.appendHit((8 + getRandom(getMaxhit())) - 8, 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + getRandom(getMaxhit()) - 5, 0);
							}
						    } else {
							if (p.equipment[13] == 11212) {
								en.appendHit(8 + (getRandom(getMaxhit()) / 2), 0);
							}
							if (p.equipment[13] == 892) {
								en.appendHit(5 + (getRandom(15) - 8), 0);
							}
						    }
						} else {
							en.appendHit(0, 0);
						}
					}
				}
				dBowSpec = false;

				if (en.equipment[5] != -1 && en.equipment[3] != 5698) {
					en.requestAnim(en.getBlockAnim(), 0);
				} else {
				    if (en.equipment[3] != 5698) {
					en.requestAnim(en.getBlockAnim1(), 0);
				    }
				}

				pm.setSpecDelay3(-1);
				return;
			    }
			}
		} catch (Exception e) {
			return;
		}
	}
	
	/**
	 * Damage dealing.
	 */
	public void appendDamages() {
		try {
			Player en = Server.engine.players[p.enemyIndex];
			if (p == null || en == null) {
				return;
			}
			PlayerMethods pm = new PlayerMethods(p);
			int playerDamage = getRandom(getMeleeMaxhit());
			int atk = Misc.random(p.meleeAtk());
			int def = Misc.random(en.meleeDef());

			if (p.fullDharok() && playerDamage >= 70) {
				en.finalBlow();
			}
			
			if (p.damageDelay == 0) {
		    	    if (en.teleDelay <= 0) {

				 // if (!Defence(p)) {

				if (atk < def) {

				    if (!p.fullVerac()) {
						en.appendHit(0, 0);
			 	    } else {
					if (getRandom(3) == 3) {
						en.appendHit((int)((playerDamage / 4) * 3), 0);
					} else {
						en.appendHit(0, 0);
					}
				    }
				} else {
					if (en.usingPrayer && en.meleePrayer) {
						if (!p.fullVerac()) {
							en.appendHit((int)((playerDamage / 4) * 2), 0);
						} else {
						    if (getRandom(3) == 3) {
							en.appendHit((int)((playerDamage / 4) * 3), 0);
						    } else {
							en.appendHit((int)((playerDamage / 4) * 3), 0);
						    }
						}
					} else {
						int guthanHealAmount = 0;
						en.appendHit(playerDamage, 0);
						guthanHealAmount = (int)((playerDamage / 4) * 3);
					    if (Misc.random(3) == 2) {
						if (p.hasGuthanEquipment()) {
							p.updateHP(guthanHealAmount, true);
							en.requestGFX(398, 0);
						}
					    }
						if (p.smitePrayer && en.skillLvl[5] > 0) {
							en.skillLvl[5] -= (int)(playerDamage / 4);
							en.frames.setSkillLvl(en, 5);
						}
						if (en.meleePrayer) {
							playerDamage -= playerDamage / 2;
						}
					}
					if (en.usingVeng) {
						p.appendHit((int)((playerDamage / 4) * 3), 0);
						en.requestForceChat("Taste Vengeance!");
						en.vengUseDelay = 0;
						en.usingVeng = false;
					}
				}
				if (en.equipment[5] != -1) {
					en.requestAnim(en.getBlockAnim(), 0);
				} else {
					en.requestAnim(en.getBlockAnim1(), 0);
				}

				pm.setDamageDelay(-1);
				pm.isGonnaDamage(false);
				return;
			    }
			}
		} catch (Exception e) {
			return;
		}
	}

	/**
	 * Holds values (used to get combat delay)
	 */
	int getCombatDelay() {
		if (p.equipment[3] >= 806 && p.equipment[3] <= 811) {
			if (p.fightStyle != 3) {
				return 2;
			} else {
				return 4;
			}
		}
		if (p.equipment[3] == 11230) {
			if (p.fightStyle != 3) {
				return 2;
			} else {
				return 4;
			}
		}
		if (p.equipment[3] == 3101) {
			return 4;
		}
		if (p.equipment[3] == 5698) {
			return 4;
		}
		if (p.equipment[3] >= 863 && p.equipment[3] <= 873) {
			return 2;
		}
		if (p.equipment[3] == 10581) {
			return 6;
		}
		if (p.equipment[3] == 1319) {
			return 7;
		}
		if (p.equipment[3] == 4153) {
			return 7;
		}
		if (p.equipment[3] == 4151) {
			return 4;
		}
		if (p.equipment[3] == 4734) {
			return 3;
		}
		if (p.equipment[3] == 9703) {
			return 5;
		}
		if (p.equipment[3] == 9705) {
			return 4;
		}
		if (p.equipment[3] == 9185) {
			return 5;
		}
		if (p.equipment[3] == 4718) {
			return 8;
		}
		if (p.equipment[3] == 11235) {
			return 8;
		}
		if (p.equipment[3] == 4755) {
			return 5;
		}
		if (p.equipment[3] == 8135) {
			return 4;
		}
		if (p.equipment[3] == 11730) {
			return 5;
		}
		if (p.equipment[3] == 4214) {
			return 4;
		}
		for (int i = 841; i <= 861; i++) {
			if (p.equipment[3] == i || p.equipment[3] == 4214)
				return 3;
		}
		if (p.equipment[3] == 4734) {
			return 3;
		}
		for (int i = 1319; i < 1334; i++) {
			if (p.equipment[3] == i || p.equipment[3] == 4587) {
				return 4;
			}
		}
		if (p.equipment[3] == 11696 || p.equipment[3] == 11694 || p.equipment[3] == 11698 || p.equipment[3] == 11700 ||
		    p.equipment[3] == 1307 ||
		    p.equipment[3] == 1309 || 
		    p.equipment[3] == 1311 || 
		    p.equipment[3] == 1313 || 
		    p.equipment[3] == 1315 ||
		    p.equipment[3] == 1317 ||
		    p.equipment[3] == 1319) {
			return 7;
		}
	return 7;
	}

	/**
	 * Holds values (used to get combat anim)
	 */
	int getCombatAnim() {
		if (p.equipment[3] == -1) {
			if (p.fightStyle != 2)
				return 422;
			else
				return 423;
		}
		if (p.equipment[3] == 4718) {
			if (p.fightStyle != 2 && p.fightStyle != 3)
				return 2067;
			else
				return 2066;
		}
		if (p.equipment[3] >= 806 && p.equipment[3] <= 811) {
			if (p.fightStyle != 3) {
				return 582;
			} else {
				return 6600;
			}
		}
		if (p.equipment[3] == 11230) {
			if (p.fightStyle != 3) {
				return 582;
			} else {
				return 6600;
			}
		}
		if (p.equipment[3] >= 863 && p.equipment[3] <= 876) {
			return 806;
		}
		if (p.equipment[3] == 10581) {
			return 402;
		}
		if (p.equipment[3] == 4726) {
			return 2080;
		}
		if (p.equipment[3] == 6528) {
			return 2661;
		}
		if (p.equipment[3] == 4153) {
			return 1665;
		}
		if (p.equipment[3] == 4734) {
			return 2075;
		}
		if (p.equipment[3] == 9703) {
			return 412;
		}
		if (p.equipment[3] == 3204) {
			return 440;
		}
		if (p.equipment[3] == 11696 || p.equipment[3] == 11694 || p.equipment[3] == 11698 || p.equipment[3] == 11700 ||
		    p.equipment[3] == 1307 ||
		    p.equipment[3] == 1309 || 
		    p.equipment[3] == 1311 || 
		    p.equipment[3] == 1313 || 
		    p.equipment[3] == 1315 ||
		    p.equipment[3] == 1317 ||
		    p.equipment[3] == 1319 || p.equipment[3] == 11730) {
			return 7041;
		}
		for (int i = 9174; i < 9186; i++) {
			if (p.equipment[3] == i) {
				return 4230;
			}
		}
		for (int i = 1265; i < 1276; i++) {
			if (p.equipment[3] == i) {
				return 401;
			}
		}
		if (p.equipment[3] == 4755) {
			return 2062;
		}
		if (p.equipment[3] == 10887) {
			return 5865;
		}
		if (p.equipment[3] == 4151) {
			return 1658;
		}
		if (p.equipment[3] == 5698) {
			return 402;
		}
		if (p.equipment[3] == 3101) {
			return 402;
		}
		for (int i = 0; i < p.rangeBows.length; i++)
			if (p.equipment[3] == p.rangeBows[i] || p.equipment[3] == 11235 || p.equipment[3] == 9705 || p.equipment[3] == 4214)
				return 426;
	return 451;
	}

	/**
	 * Sets npc attacking.
	 * @param attackingNpc if player is attacking npc. return true.
	 */
	public void setNpcAttack(boolean attackingNpc) {
		p.attackingNpc = attackingNpc;
	}

	/**
	 * Sets npc attack delay
	 * @param atkDelay the delay which is gonna be set.
	 */
	public void setAtkDelay(int atkDelay) {
		p.atkDelay = atkDelay;
	}

	/**
	 * Sets damage delay.
	 * @param damageDelay1 the delay which is gonna be setted.
	 */
	public void setNpcDamageDelay(int damageDelay1) {
		p.damageDelay1 = damageDelay1;
	}

	public void setEnableDamageNpc(boolean enableDamage) {
		p.enableDamage = enableDamage;
	}

	/**
	 * Once damage delay reaches 0 this method gets activated.
	 */
	public void appendNpcDamageMelee() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null || n.playerIndex == -1 || n.currentHP <= 0) {
			p.resetAttack();
			return;
		}
		NpcCombat npcCombat = new NpcCombat(n);
		int npcDamage = getRandom(getMeleeMaxhit());
		int npcDamage2 = getRandom(getRangeHit());
		try {
			if (npcDamage <= 0 || npcDamage2 <= 0)
				npcDamage = npcDamage2 = 0;
			if (n.npcType != 2745 && n.npcType != 4284 && n.npcType != 2746)
				n.playerIndex = p.playerId;
			else
				n.spawnedFor = p.playerId;
			if (n.npcType == 6247)
				p.disturbSara = true;
			if (n.npcType == 2736 || n.npcType == 2737)
				p.appendHit(1, 0);
			if (!usingRange()) {
				if (p.damageDelay1 == 0) {
					if (n.changeAnimDelay <= 0)
						n.requestAnim(npcCombat.getBlockAnim(), 0);
					n.playerIndex = p.playerId;
					n.underAttack = true;
					n.battleCDelay = 7;
					if (n.battleCount <= 0)
						n.battleCount++;	
					if (p.equipment[3] == 10581) {
						for (int i = 0; i < n.kalphiteMonsters.length; i++) {
							if (n.npcType == n.kalphiteMonsters[i]) {
								n.appendHit(npcDamage * 12, 0);
								if (p.fightStyle == 1)
									p.appendExperience(npcDamage * 450, 0);
								if (p.fightStyle == 2)
									p.appendExperience(npcDamage * 450, 2);
								if (p.fightStyle == 3)
									p.appendExperience(npcDamage * 450, 2);
								if (p.fightStyle == 4)
									p.appendExperience(npcDamage * 450, 1);
								p.appendExperience(npcDamage *215, 3);
								p.damageDelay1 = -1;
								p.enableDamage = false;
								return;
							}
						}
					}
					if (getRandom(p.equipmentBonus[10]) > getRandom(getNpcDefence())) {
						if (n.npcType == 7771) {
							if (p.meleePrayer)
								p.appendHit(15, 0);
							for (int i = 0; i <= p.miningAxes.length; i++) {
								if (p.equipment[3] != p.miningAxes[i]) {
									n.appendHit(0, 0);
								} else {
									n.appendHit(npcDamage, 0);
									n.brokenArmour--;
								}
							}
						} else {
							n.appendHit(npcDamage, 0);
						}
						if (p.fightStyle == 1)
							p.appendExperience(npcDamage * 120, 0);
						if (p.fightStyle == 2)
							p.appendExperience(npcDamage * 120, 2);
						if (p.fightStyle == 3)
							p.appendExperience(npcDamage * 120, 2);
						if (p.fightStyle == 4)
							p.appendExperience(npcDamage * 120, 1);
						p.appendExperience(npcDamage * 75, 3);
					} else {
						if (n.npcType == 7771) {
							if (p.meleePrayer)
								p.appendHit(15, 0);
							for (int i = 0; i <= p.miningAxes.length; i++) {
								if (p.equipment[3] != p.miningAxes[i]) {
									n.appendHit(0, 0);
								} else {
									n.appendHit(0, 0);
									n.brokenArmour--;
								}
							}
						} else {
							n.appendHit(0, 0);
						}
					}
					p.damageDelay1 = -1;
					p.enableDamage = false;
				}
			} else {
				if (p.damageDelay1 == 0) {
					n.playerIndex = p.playerId;
					n.underAttack = true;
					n.requestAnim(npcCombat.getBlockAnim(), 0);
					if (!p.hitNpcRange()) {
						n.appendHit(0, 0);
						if (p.equipment[3] == 11235)
							n.appendHit(0, 0);
					} else {
						n.appendHit(npcDamage2, 0);
						if (p.equipment[3] == 11235)
							n.appendHit(npcDamage2, 0);
						p.appendExperience(npcDamage * 90, 4);
						p.appendExperience(npcDamage * 90, 3);
					}
					p.damageDelay1 = -1;
					p.enableDamage = false;
				}
			}
		} catch (Exception e) {
			p.resetAttack();
			p.enableDamage = false;
			p.damageDelay1 = -1;
			return;
		}
	}

	/**
	 * (Special attk) Once damage delay reaches 0 this method gets activated.
	 */
	public void appendNpcDamageMeleeSpec() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null || n.playerIndex == -1 || n.currentHP <= 0) {
			p.resetAttack();
			return;
		}
		try {
			int npcDamage = getRandom(getMaxhit());
			if (n.npcType != 2745 && n.npcType != 4284 && n.npcType != 2746)
				n.playerIndex = p.playerId;
			else
				n.spawnedFor = p.playerId;
			if (n.npcType == 6247)
				p.disturbSara = true;
			if (npcDamage <= 0)
				npcDamage = 0;
			if (n.npcType == 2736 || n.npcType == 2737)
				p.appendHit(1, 0);
			if (!usingRange()) {
				if (p.damageSpecDelay == 0) {
					n.playerIndex = p.playerId;
					n.underAttack = true;
					n.battleCDelay = 7;
					if (n.battleCount <= 0)
						n.battleCount++;
					if (!hasAccuracy()) {
						if (getRandom(p.equipmentBonus[11]) > getRandom(n.meleeDef + getNpcDefence())) {
							if (n.npcType == 7771) {
								if (p.meleePrayer)
									p.appendHit(15, 0);
								n.appendHit(0, 0);
							} else {
								n.appendHit(npcDamage, 0);
							}
							if (p.equipment[3] == 5698 || p.equipment[3] == 11730 || p.equipment[3] == 3204 || p.equipment[3] == 3101) {
								if (n.npcType == 7771) {
									if (p.meleePrayer)
										p.appendHit(15, 0);
									n.appendHit(0, 0);
								} else {
									n.appendHit(npcDamage, 0);
								}
							}
							p.appendExperience(npcDamage * 100, 2);
						} else {
							n.appendHit(0, 0);
							if (p.equipment[3] == 5698 || p.equipment[3] == 11730 || p.equipment[3] == 3204 || p.equipment[3] == 3101) {
								n.appendHit(15, 0);
							}
						}
					} else {
						if (n.npcType == 7771) {
							if (p.meleePrayer)
								p.appendHit(15, 0);
							n.appendHit(0, 0);
						} else {
							n.appendHit(getRandom(getMaxhit()), 0);
						}
						p.appendExperience(npcDamage * 4, 2);
					}
					p.damageSpecDelay = -1;
					p.enableSpecDamage = false;
				}
			} else {
				if (p.damageDelay == 0) {
					n.playerIndex = p.playerId;
					n.underAttack = true;
					n.appendHit(getRandom(getMaxhit()), 0);
					if (p.equipment[3] == 11235) {
						n.appendHit(getRandom(getMaxhit()), 0);
						n.requestGFX(1100, 100);
					}
					p.damageSpecDelay = -1;
					p.enableSpecDamage = false;
				}
			}
		} catch (Exception e) {
			p.resetAttack();
			p.damageSpecDelay = -1;
			p.enableSpecDamage = false;
			return;
		}
	}

	int getNpcDefence() {
		NPC n = Server.engine.npcs[p.attackNpc];
		switch (n.npcType) {

			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				return 6;
			case 81: return 0;
			case 50: return 190;
			case 117: return 5;
			case 134: return 100;
			case 907: return 120;
			case 1153: return 60;
			case 1154: return 100;
			case 1155: return 130;
			case 1156: return 50;
			case 1157: return 120;
			case 5253: return 220;
			case 1158:
				if (p.fullVerac())
					return 120;
				else
					return 240;
			case 1160:
				if (p.fullVerac())
					return 95;
				else
					return 225;
			case 3847: return 290;
			case 1615: return 120;
			case 5363: return 320;
			case 5902: return 260;
			case 2745: return 240;
			case 2744: return 165;
			case 2746: return 10;
			case 1472: return 180;
			case 4284: return 100;
			case 4291: return 140;
			case 4292: return 153;
			case 6203: return 330;
			case 6222: return 340;
			case 6223: return 320;
			case 6225: return 300;
			case 6227: return 330;
			case 6247: return 340;
			case 6260: return 340;
			case 6625: return 230;
			case 6691: return 250;
			case 6729: return 260;
			case 6998: return 220;	
			case 6999: return 210;
			case 7770: return 200;
			case 7771: return 400;

			default:
				return 80;
		}
	}

	int getProjectile() {
		switch (p.equipment[13]) {

			case 882:
				return 10;
			case 892:
				return 15;
			case 11212:
				return 1120;

			case 4740:
			case 9141:
			case 9143:
			case 9144:
			case 9244:
				return 27;

			case 9706:
				return 16;

			case -1:
				if (p.equipment[3] == 4214)
					return 249;

			default:
				return -1;
		}
	}

	int getProjSpeed() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null)
			return 150;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 1)
			return 65;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 2)
			return 68;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 3)
			return 70;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 4)
			return 72;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 5)
			return 74;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 6)
			return 76;
	return 73;
	}

	int getRangeDamageDelayPk() {
		Player p2 = Server.engine.players[p.enemyIndex];
		if (p == null || p2 == null) {
			return -1;
		}
		/*if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 1)
			return 2;
		if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 2)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 3)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 4)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 5)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, p2.absX, p2.absY) == 6)
			return 2;*/
	return 3;
	}

	int getRangeDamageDelay() {
		NPC n = Server.engine.npcs[p.attackNpc];
		if (p == null || n == null)
			return 150;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 1)
			return 2;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 2)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 3)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 4)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 5)
			return 3;
		if (Misc.getDistance(p.absX, p.absY, n.absX, n.absY) == 6)
			return 2;
	return 3;
	}

	public int getNpcDefenceRange() {
		NPC n = Server.engine.npcs[p.attackNpc];
		switch (n.npcType) {

			case 1:
			case 2:
			case 3:
			case 4:
			case 5:
			case 6:
				return 3;

			case 134: return 90;
			case 1158: return 520;
			case 1160: return 180;
			case 1615: return 140;
			case 2614: return 230;
			case 5902: return 280;
			case 5253: return 190;
			case 6223: return 195;
			case 6225: return 210;
			case 6227: return 200;
			case 6222: return 190;
			case 6260: return 340;
			case 6261: return 230;
			case 6263: return 250;
			case 3847: return 230;
			case 1472: return 240;
			case 2745: return 130;
			case 2746: return 10;
			case 4284: return 150;
			case 4291: return 90;
			case 4292: return 95;
			case 6265: return 240;
			case 6625: return 150;
			case 6729: return 170;
			case 6247: return 290;
			case 6691: return 190;
			case 6998: return 180;	
			case 6999: return 160;
			case 7770: return 180;
			case 7771: return 420;

			default:
				return 20;
		}
	}

	public int getWepSound() {
		switch (p.equipment[3]) {

			case 861:
				return 2693;
			case 859:
				return 2693;
			case 857:
				return 2693;
			case 855:
				return 2693;
			case 853:
				return 2693;
			case 851:
				return 2693;
			case -1:
				return 2564;
			case 4151:
				return 2720;
			case 4726:
				return 1328;
			case 4755:
				return 1323;
			case 4747:
				return 1332;
			case 4675:
				return 2555;
			case 6528:
				return 2520;
			case 4587:
			case 1305:
				return 2500;
			case 4718:
				return 1321;
			case 5698:
				return 2517;
			case 4734:
			case 9185:
				return 2700;
			case 868:
				return 2696;
			case 11235:
				return 3731;
			case 11694:
			case 11696:
			case 11698:
			case 11700:
			case 11730:
				return 3846;	
		    default:
			return 10000;
		}
	}

    	private int getRandom(int range) {
        	return (int)(Math.random() * (range + 1));
    	}

	public boolean dBowSpec;
	public boolean crossBowDragon;

	private int[] godSwords = {
	};

}